home *** CD-ROM | disk | FTP | other *** search
- Path: news.rain.org!usenet
- From: "Guus Leeuw jr." <guusl@eiffel.com>
- Newsgroups: comp.lang.c++
- Subject: Re: help: templates + destructors
- Date: Tue, 12 Mar 1996 08:33:28 -0800
- Organization: Interactive Software Engineering Inc. http://www.eiffel.com/
- Message-ID: <3145A758.EDB77B0@eiffel.com>
- References: <klEd_y200iWTM=AEsS@andrew.cmu.edu>
- NNTP-Posting-Host: @outback.eiffel.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (X11; I; Linux 1.2.8 i586)
-
- Matthew Edward Patton wrote:
- >
- [snip snip]
- >
- > template<class T>
- > class field {
- > T value;
- > public:
- > field(void) { value = (T) 0; };
- > field(byte) { value = (T) 0; };
- > ~field(void) { return; };
- > }
- >
- > field<char*>::field(void) {
- > // override class default;
- > }
- > field<char*>::field(byte length) {
- > //override class default;
- > value = new char[length];
- > }
- >
- > field<char *>::~field(void) {
- > delete[] value;
- > }
- >
- > The error:
- > no 'field' member function declared in class 'field<char*>'
- >
- > I took that to mean the compiler can't define a custom destructor if a
- > custom constructor doesn't already exist. Thing is, I've got two
- > constructors defined. I appreciate your help.
-
- Nope. You declared your class as being template <class T>. In your
- definition you'll have to say:
-
- template <class T>
- field<T>::field(void) {
- ..
- }
-
- template <class T>
- field<T>::field (byte length) {
- ..
- }
-
- template <class T>
- field<T>::~field(void) {
- ..
- }
-
- Then, when you want to use it, you say:
-
- class A {
- field<char*> _my_field; // Instatiation of a field
- // holding a char*
- }
-
- Hope this helps,
- Guus
-